package logmanager.view_connection;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

//classe de lecture de fichier avec bufferisation

public class TextReader {
	private InputStream is = null;
	private BufferedReader br = null;
	private String fileName=null;
	
	public TextReader(String fileName) throws FileNotFoundException{
		this.fileName = fileName;
		is = new FileInputStream(fileName);
		InputStreamReader isr = new InputStreamReader(is);
		br = new BufferedReader(isr);
	}
	
//fermer le fichier
	public void close() throws IOException{
		br.close();
	}
	
//lit un caractere du fichier
	public char readChar() throws IOException{
		char c = 0;
		c = (char) br.read();
		return c;
	}
	
//lire tt le fichier
	public String readAll() throws IOException{
		String s = null, t = "";
		s = readLine();
		int n = 0;
		while(s != null){
			if(n==0)
				t = s;
			else
				t = t + "\n" + s;
			s = readLine();
			n++;
		}
		return t;
	}
	
public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	//lit une ligne du fichier
	public String readLine() throws IOException{
		String s = null;
		s = br.readLine();
			
		if((s + "").equals("null")){
			return s + "";
		}
		return s;
	}
}
